<template>
	<view>
		<u-popup mode='bottom' :show="adrOpen" :overlay="true" :closeable="false" :round="15"
			:closeOnClickOverlay="true" @close="adrOpen = false">
			<view class="flex-colume-start adrListBox" style="height: 72vh;">
				<view class="flex-row-start header1">
					<image @click="adrOpen = false" src="/static/arrow/close-gray.png" class="close1"></image>
					<view style="font-size: 26rpx;" @click="adrAddClick">+新增地址</view>
				</view>
				<view style="height: calc(100% - 60rpx); width: 100vw;">
					<u-list style="height: 100%; width: 100vw;">
						<view style="width: 100%; height: 100%;">
							<view class="flex-row-start adrItem" v-if="adrList && adrList.length > 0" v-for="(item,index) in adrList" :key="index">
								<view @click="leftBtnClick(item)" class="flex-colume-start left3">
									<view class="adr1">{{item.province_name}} {{item.city_name}} {{item.quan_id}}</view>
									<view class="adr2 text-two-line">{{item.address}}</view>
									<view class="flex-row-start adr3">{{item.consignee}} {{item.telephone}}
									<span v-if="[1,'1'].indexOf(item.is_default) != -1">默认</span>
									</view>
								</view>
								<view class="flex-row-start right1">
									<image @click="adrEditClick(item)" src="/static/mine/adr-edit.png"></image>
									<image @click="adrDeleteClick(item)" src="/static/mine/adr-del.png"></image>
								</view>
							</view>
							<view v-else style="font-size: 25rpx; width: 100%; line-height: 400rpx; text-align: center;">
								暂无收货地址
							</view>
						</view>
						
						
					</u-list>
				</view>
				<view style="height: 30rpx;"></view>
				
				
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { adrList, adrDel } from '@/api/api';
	export default {
		name:"adrList",
		data() {
			return {
				adrOpen:false,
				adrList:[]
				
			};
		},
		methods:{
			init(e){
				this._pageKey = e
				if (this.adrList.length == 0){
					this.requestAdrList()
				}
				this.adrOpen = true
			},
			requestAdrList(){
				adrList({}).then(res=>{
					if (res.code == 200){
						this.adrList = res.data
					}
				})
			},
			adrDeleteClick(item){
				uni.showModal({
					content:'确定删除',
					complete:res=>{
						if (res.confirm){
							uni.showLoading({
								mask:true
							})
							adrDel({id:item.id}).then(res1=>{
								if (res1.code == 200){
									this.requestAdrList()
								}
								uni.showToast({
									icon:'none',
									title:res1.message
								})
								setTimeout(res2=>{
									uni.hideLoading()
								},2000)
								
							})
							
						}
					}
				})
			},
			leftBtnClick(item){
				
				if (this._pageKey == 'adrSel'){
					uni.$emit('adrSel',item)
					this.adrOpen = false
				}
				
				
			},
			adrEditClick(item){
				uni.$once('adrUpt',res=>{
					this.requestAdrList()
				})
				uni.setStorageSync('adrDetail',item)
				uni.navigateTo({
					url:'/pages/mine/adrAdd?id='+item.id
				})
				
			},
			adrAddClick(){
				uni.$once('adrUpt',res=>{
					this.requestAdrList()
				})
				uni.navigateTo({
					url:'/pages/mine/adrAdd'
				})
			
			}
		}
	}
</script>

<style lang="scss" scoped>


	.adrListBox{
		width: 100%;
		padding: 20rpx 0rpx calc(env(safe-area-inset-bottom) + 30rpx) 0rpx;
		.header1{
			font-size: 0px;
			color: #C90000;
			width: 100%;
			padding: 0rpx 25rpx;
			justify-content: space-between;
			box-sizing: border-box;
			.close1{
				
				width: 50rpx;
				height: 50rpx;
				padding: 16rpx;
				box-sizing: border-box;
			
			}
		}
		
		.adrItem{
			width: 100%;
			padding: 25rpx;
			position: relative;
			border-bottom: 1px solid rgb(230, 230, 230);
			.right1{
				position: absolute;
				top: 0rpx;
				right: 0rpx;
				height: 100%;
				width: 150rpx;
				font-size: 0rpx;
				justify-content: flex-end;
				padding-right: 10rpx;
				image{
					width: 50rpx;
					height: 50rpx;
					padding: 5rpx;
					margin-right: 10rpx;
				}
			}
			.left3{
				width: 550rpx;
				align-items: flex-start;
				.adr1{
					line-height: 32rpx;
					margin-bottom: 12rpx;
					font-size: 28rpx;
					color: rgb(153, 153, 153);
				}
				.adr2{
					line-height: 32rpx;
					margin-bottom: 12rpx;
					font-size: 28rpx;
					max-width: 500rpx;
					
				}
				.adr3{
					padding: 0rpx;
					line-height: 32rpx;
					font-size: 28rpx;
					span{
						margin-left: 20rpx;
						color: white;
						font-size: 20rpx;
						height: 32rpx;
						line-height: 32rpx;
						padding: 0rpx 10rpx;
						box-sizing: border-box;
						background-color: #C90000;
						border-radius: 4rpx;
					}
					
				}
			}
		}
		
		
	}

</style>